package models

import (
	"gorm.io/gorm"
	"pro/global"
)

type Videos struct {
	gorm.Model
	Title  string `gorm:"type:varchar(30);comment:'视频标题'"`
	Author string `gorm:"type:varchar(20);comment:'作者'"`
	Tags   string `gorm:"type:varchar(10);comment:'标签'"`
	Url    string `gorm:"type:varchar(255);comment:'视频地址'"`
	Likes  int64  `gorm:"type:int(7);comment:'点赞数'"`
	Visit  int64  `gorm:"type:int(7);default:1;comment:'浏览次数'"`
	Status int64  `gorm:"type:int(1);default:1;comment:'状态1-待审核 2-审核通过 3-审核未通过'"`
}

func (v *Videos) AddVideo() error {
	return global.DB.Create(&v).Error
}

func (v *Videos) GetVideoInfoById(id int) error {
	return global.DB.Where("id=?", id).Limit(1).Find(&v).Error
}

//func (v *Videos) SearchVideo() (listVideo []Videos,err error) {
//
//}

func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if page <= 0 {
			page = 1
		}

		switch {
		case pageSize > 100:
			pageSize = 100
		case pageSize <= 0:
			pageSize = 10
		}

		offset := (page - 1) * pageSize
		return db.Offset(offset).Limit(pageSize)
	}
}

// 点赞表
type UserLikesLog struct {
	gorm.Model
	UserId  int64 //用户ID
	VideoId int64 //视频ID
}

// 收藏表
type BestLike struct {
	gorm.Model
	UserId  int64 //用户ID
	VideoId int64 //视频ID
}

type ShareVideo struct {
	UserId  int64 //用户ID
	VideoId int64 //视频ID
	DistId  int64 //对方ID
}

// 评论表
type VideoComment struct {
	gorm.Model
	UserId  int64  //用户ID
	VideoId int64  //视频ID
	Comment string //评论内容
}
